package com.bluesky.admin.controller.system;

import com.alibaba.fastjson.JSONObject;
import com.bluesky.common.dto.LoginDTO;
import com.bluesky.common.result.R;
import com.bluesky.framework.web.service.IUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 登录 前端控制器
 * </p>
 *
 * @author Kevin
 */
@RestController
public class LoginController {

    @Resource
    IUserService userService;

    @PostMapping("/login")
    public R login(@Validated @RequestBody LoginDTO req) {
        String token = userService.login(req);
        JSONObject result = new JSONObject();
        result.put("token", token);
        return R.success(result);
    }

    @GetMapping("/getUserInfo")
    public R getUserInfo() {
        return R.success(userService.getUserInfo());
    }

    @GetMapping("/getPermCode")
    public R getPermCode() {
        return R.success(userService.getPermCode());
    }

    @GetMapping("/getMenuList")
    public R getMenuList() {
        return R.success(userService.getMenuList());
    }

}
